package org.jeecg.modules.api.task;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.api.member.service.IMemberService;
import org.jeecg.modules.api.officebalancelog.service.IOfficeBalanceLogService;
import org.jeecg.modules.api.order.dto.CreateFxOrderReq;
import org.jeecg.modules.api.order.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 完成的订单，分佣奖励定时任务
 */
@Component
@Slf4j
public class FxOrderTask {

    @Autowired
    private IOfficeBalanceLogService officeBalanceLogService;
    @Autowired
    private IOrderService orderService;


    /**
     *
     */
    @Scheduled(cron = "0/30 * * * * *")
    public void orderTask() {
        try {
            List<String> list = officeBalanceLogService.getFxOrderList();
            for (String orderId : list) {
                CreateFxOrderReq req = new CreateFxOrderReq();
                req.setOrderId(orderId);
                Result result = orderService.createFxOrder(req);
                log.info("result:{}", JSONObject.toJSONString(result));
            }
        } catch (Exception e) {
            log.error("{}", e);
        }
    }

}
